package com.cayden.config.boot.component;


import com.cayden.base.exception.CaydenBaseException;
import com.cayden.componets.aop.factory.AopContain;
import com.cayden.config.boot.Apps;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.InitializingBean;

import java.util.Map;

/**
 * @author cayden
 * @date 2021-10-25 17:13
 * aop 基础控制，所有的切面类都需要继承当前类
 */
public class AopComponentRole implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {
        Map<String, Object> beansWithAnnotation = Apps.getApplicationContext().getBeansWithAnnotation(Aspect.class);
        for (String key : beansWithAnnotation.keySet()) {
            Object targetAspectObject = beansWithAnnotation.get(key);
            String objectPath = targetAspectObject.getClass().getName();
            if (!(beansWithAnnotation.get(key) instanceof AopContain)){
                throw new CaydenBaseException(objectPath + ": Aop 是实现必须实现自 AopContain");
            }
        }
    }
}
